<?php
//+--------------------------------------------
//|描述
//|--------------------------------------------
//|Created by PhpStorm.
//| Author: DRG
//+-------------------------------------------
//|Date: 2018/5/29
//| Time: 8:54
//+--------------------------------------------

$server = new swoole_websocket_server("0.0.0.0", 8812);

$server->on('open','onOpen');

//监听websocket 连接事件
function onOpen( $server, $request) {
//    echo "server: handshake success with fd{$request->fd}\n";
    print_r($request->fd);
}
//监听 wx  消息事件
$server->on('message', function (swoole_websocket_server $server, $frame) {
    echo "receive from {$frame->fd}:{$frame->data},opcode:{$frame->opcode},fin:{$frame->finish}\n";
    $server->push($frame->fd, "duruigang-push-server");
    //push   长度不超过2M
});

$server->on('close', function ($ser, $fd) {
    echo "client {$fd} closed\n";
});

$server->start();